package com.example.topguli;

import java.util.concurrent.locks.ReentrantReadWriteLock;

public class LowLockTest {
    ReentrantReadWriteLock lock=new ReentrantReadWriteLock();
    public static void main(String[] args) {
        LowLockTest lowLockTest = new LowLockTest();
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
         lowLockTest.lowLock();
            }).start();
        }
    }
    public void lowLock(){
        ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
        ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
        writeLock.lock();
        readLock.lock();
        try {
            System.out.println("降级锁测试");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            System.out.println("写锁释放");
            writeLock.unlock();
            System.out.println("读锁释放");
            readLock.unlock();
        }
    }
}
